import { View } from "../../../../mvc/core/View";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { SApplyMsg } from "../../../../../Message/Game/SApplyMsg";
import { PlayerMiniInfo } from "../../../model/PlayerMiniInfo";
import { EntityUtil } from "../../../scene/layer/utils/EntityUtil";
import { FriendRequestWindow } from "../FriendRequestWindow";
import { EffectManager } from "../../../manager/EffectManager";
import { UIIconEvent } from "../../uiIconBtn/UIIconEvent";
import { DataEvent } from "../../../events/DataEvent";
type int = number;
//class FriendAddIcon
    
    export  class FriendAddIcon extends View
    {
        constructor()
        {
            super();
            this.buttonMode = true;
            this._aryRequest = new Array<any>();
            this.initView();
            this.addListeners();
            return;
        }

        public set labelTxt(arg1: string)
        {
            this._labelTxt.text = arg1;
            this.textFormat = new GTextFormat(FontUtil.songtiName, 10, 16777215);
            this._labelTxt.setTextFormat(this.textFormat);
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=GlobalClass.getBitmap(ImagesConst.Friend_hintIcon);
            this.addChild(loc1);
            this._labelTxt = new Object /* flash.text.TextField */();
            this._labelTxt.selectable = false;
            this._labelTxt.filters = [FilterConst.glowFilter];
            this._labelTxt.width = loc1.width;
            this._labelTxt.height = 10;
            this._labelTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._labelTxt.y = loc1.height - 14;
            addChild(this._labelTxt);
            return;
        }

        /* internal  */addListeners(): void
        {
            this.addEventListener(flash.events.MouseEvent.CLICK, this.showReplyWindow);
            Dispatcher.addEventListener(EventName.FriendDelRequest, this.onFriendDelRequestHandler);
            Dispatcher.addEventListener(EventName.FriendDelAllRequest, this.onFriendDelAllRequestHandler);
            return;
        }

        public showIcon(arg1: SApplyMsg): void
        {
            var loc2=null;
            var loc1=new PlayerMiniInfo(arg1.fromPlayer);
            var loc3=0;
            var loc4=this._aryRequest;
            for(loc2 of loc4) 
            {
                if (EntityUtil.toString(loc2.fromPlayer.entityId) != EntityUtil.toString(loc1.entityId)) 
                {
                    continue;
                }
                return;
            }
            this._aryRequest.push(arg1);
            this.labelTxt = String(this._aryRequest.length);
            this.show();
            return;
        }

        /* internal  */showReplyWindow(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.labelTxt = String(this._aryRequest.length);
            if (this._requestWindow == null) 
            {
                this._requestWindow = new FriendRequestWindow();
            }
            if (this._aryRequest.length > 0) 
            {
                this._requestWindow.updateDataProvider(this._aryRequest);
                if (arg1) 
                {
                    this._requestWindow.show();
                }
            }
            else 
            {
                if (this.parent) 
                {
                    this.parent.removeChild(this);
                    EffectManager.glowFilterUnReg(this);
                    this.dispatchEvent(new UIIconEvent(UIIconEvent.RemoveIcon));
                }
                this._requestWindow.hide();
            }
            return;
        }

        /* internal  */onFriendDelRequestHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=arg1.data as int;
            var loc4=0;
            var loc5=this._aryRequest;
            for(loc2 of loc5) 
            {
                if (loc2.fromPlayer.entityId.id != loc1) 
                {
                    continue;
                }
                loc3 = this._aryRequest.indexOf(loc2);
                this._aryRequest.splice(loc3, 1);
                this.showReplyWindow(null);
                break;
            }
            return;
        }

        /* internal  */onFriendDelAllRequestHandler(arg1: DataEvent): void
        {
            this._aryRequest = [];
            this.showReplyWindow(null);
            return;
        }

        /* internal */ /* var */_aryRequest: Array<any>;

        /* internal */ /* var */_labelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */textFormat: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_requestWindow: FriendRequestWindow;
    }
